package edu.gzy.rpsm_property.mapper;

import edu.gzy.rpsm_property.pojo.Building;
import org.apache.ibatis.annotations.*;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.stereotype.Repository;

import java.util.List;

//@Mapper
@Repository
public interface BuildingMapper {

    @Select("<script>" +
            "SELECT building_id, building_name FROM building " +
            "<where>" +
            "   <if test='status != 0'> building_status = #{status} </if>" +
            "</where>" +
            "</script>")
    List<Building> buildingsOfStatus(@Param("status") int status);

    @Insert("INSERT INTO building (building_id, building_name, building_code, building_status, building_floors, completed_date, design_life, ownership) " +
            "VALUES (#{building_id}, #{building_name}, #{building_code}, #{building_status}, #{building_floors}, #{completed_date}, #{design_life}, #{ownership})")
    int insertBuilding(Building building);

    @Update("<script>" +
            "UPDATE building SET building_status = #{status} WHERE building_id IN " +
            "<foreach collection='idList' item='id' open='(' separator=',' close=')'>" +
            "   #{id}" +
            "</foreach>" +
            "</script>")
    int changeBuildingStatus(@Param("idList") List<Integer> idList, @Param("status") Integer status);

    int insertBuildings(List<Building> buildings);  // 批量插入方法

    @Select("<script>" +
            "select * from building where building_id = #{id}" +
            "</script>")
    Building queryById(Integer id);
}
